/*
 * Copyright 2007-208 the original author or authors.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */ 
package com.cassevern.storproc.util;
import groovy.text.*


class BuildCallBeansFromStorProcTest extends GroovyTestCase {

	void testSomething() {
		def builder = new BuildCallBeansFromStorProc(
				ip:'172.16.1.4', 
				user:'dgd', 
				password:'vo2max', 
				library:'dgd', 
				procName:'getaccts', 
				handleResultSet:true)
//		def conn = builder.getConnection()
//		builder.isProcedureAvail(conn) 
//		def list = builder.getParmAttrList(conn)
		def list = []
		list << new ParmAttr(name:'countin',    colType:2,type:'DECIMAL',  length:0, precision:5,scale:0)
		list << new ParmAttr(name:'errorin',    colType:2,type:'CHARACTER',length:1, precision:0,scale:0)
		list << new ParmAttr(name:'errormsgin', colType:2,type:'CHARACTER',length:50,precision:0,scale:0)
		def inputParms = list.findAll { it.colType in 1..2 }
		def outputParms =   list.findAll { it.colType in 2..3 }

		def sqlCallStatement = builder.getSQLCallStatement(inputParms)
		println "sqlCallStatement: $sqlCallStatement"
		def procNameCamelCase = builder.procName.substring(0,1).toUpperCase() + builder.procName.substring(1).toLowerCase()

		def file = new File("src/com/cassevern/storproc/util/RpgCallJavaBeanResultGUI.template")
		def binding = [inputParms:inputParms, outputParms:outputParms,
		               ip:builder.ip,user:builder.user,password:builder.password,library:builder.library,
		               procNameCamelCase:procNameCamelCase,sqlCallStatement:sqlCallStatement,handleResultSet:false
		               ]
		def writable = new SimpleTemplateEngine().createTemplate(file).make(binding)
		GroovyShell shell = new GroovyShell()
		shell.evaluate(writable.toString())
		print writable.toString()


	}

}
